﻿
///////////////////////////////////////////////////////////
//This code is taken from the Channel9 video tutorials.
//They are here for convenience - check the web link in the
//folder for each of these to see the original postings.
//
//These challenges are completed - the uncompleted ones are in
//a subfolder below this one, named OriginalCode
//////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reactive.Concurrency;
using System.Threading.Tasks;
using System.Threading;

namespace Schedulers
{
    class MyHistoricalScheduler : HistoricalScheduler
    {
        public void Run(TimeSpan delay)
        {
            Scheduler.ThreadPool.Schedule(
                delay,
                self =>
                {
                    var next = GetNext();
                    if (next == null)
                        return;
                    var dt = next.DueTime;
                    AdvanceTo(dt);
                    self(delay);
                });
        }
    }
}
